package com.mtung.concurrent;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

/**
 * @author zhenguo.yao
 * @date 2020/12/20
 */
@Service
public class AsyncService {

    @Async
    public void sendSms() throws InterruptedException {
        Thread.sleep(5000);
        System.out.println(Thread.currentThread().getName() + "发送短信");
    }

    @Async
    public Future<String> sendFutureSms() throws InterruptedException {
        Thread.sleep(5000);
        System.out.println(Thread.currentThread().getName() + "发送短信");
        return new AsyncResult<>("Thread.currentThread().getName() + \"发送短信\"");
    }

}
